package com.BaiBai.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(2)//值越大，优先级越低，前置后执行，后置先执行
public class TxAdvice {
    @Around("com.BaiBai.pointcut.MyPointcut.pc()")
    public Object surround(ProceedingJoinPoint joinPoint){
        Object[] args= joinPoint.getArgs();
        Object result=null;
        try {
            System.out.println("事务开始");
            result=joinPoint.proceed(args);
            System.out.println("事务提交");
        } catch (Throwable throwable) {
            System.out.println("事务回滚");
        }finally {
            System.out.println("释放资源");
        }
        return result;
    }
}
